package com.boang.log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

/*
  @author: 13813
  @date: 2024/7/24 14:24
*/
@Aspect //切面
@Component
public class Logger {

    /*
        public List<Cla> com.boang.service.ClaServiceImpl.getClaList(..)
        权限修饰符 *
        * List<Cla> com.boang.service.ClaServiceImpl.getClaList(..)
        返回类型 *
        * * com.boang.service.ClaServiceImpl.getClaList(..)
        权限修饰符 * 可以省略
        * com.boang.service.ClaServiceImpl.getClaList(..)
        包名 *
        * *.*.*.ClaServiceImpl.getClaList(..)
        包名 .. 当前包及其子包
        * *..ClaServiceImpl.getClaList(..)
        类名 *
        * *..*.getClaList(..)
        方法名 *
        * *..*.*(..)
        参数 ..
        * *..*.*(..)
     */

    //切入点表达式
    @Pointcut("execution(* com.boang.service.ClaServiceImpl.getClaList(..))")
    public void pt() {
    }

    /*@Before("pt()") //前置通知
    public void beforeLog() {
        System.out.println("beforeLog");
    }

    @After("pt()") //后置通知
    private void afterLog() {
        System.out.println("afterLog");
    }

    @AfterThrowing("pt()") //异常通知
    public void afterThrowingLog() {
        System.out.println("afterThrowingLog");
    }

    @AfterReturning("pt()") //最终通知
    public void afterReturningLog() {
        System.out.println("afterReturningLog");
    }*/

    @Around("pt()")
    public void around(ProceedingJoinPoint pp) {
        try {
            System.out.println("环绕-前置");
            pp.proceed(); //调用目标方法
            System.out.println("环绕-后置");
        } catch (Throwable e) {
            System.out.println("环绕-异常");
        } finally {
            System.out.println("环绕-最终");
        }
    }
}
